import { createRouter, createWebHistory, createWebHashHistory } from "vue-router";
import HelloWorld from "@/components/HelloWorld.vue";
import Login from "@/view/Login.vue";
import List from "@/view/List.vue"
import User from "@/view/User.vue"

const routerHistory = createWebHashHistory();
// createWebHashHistory hash 路由
// createWebHistory history 路由
// createMemoryHistory 带缓存 history 路由
const router = createRouter({
    history: routerHistory,
    routes: [
        {
            path: "/",
            component: Login,
            meta: { title: "登录 - 文件管理系统" }
        },
        {
            path: "/list",
            component: List,
            meta: { title: "文件 - 文件管理系统" }
        },
        {
            path: "/user",
            component: User,
            meta: { title: "用户 - 文件管理系统" }
        }
    ],
});


router.beforeEach((to, from, next) => {
    /* 路由发生变化修改页面title */
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    next();
});

export default router;